﻿using Microsoft.Win32;
using Habi.Solver.Helpers;
using Habi.Solver.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Habi.Solver.ViewModels
{
    public class DashboardViewModel
    {
        public virtual IList<AppModel> Apps { get; set; }

        public virtual AppModel ActivedAppModel { get; set; }

        public void OnActivedAppModelChanged(AppModel model)
        {
            Console.WriteLine(ActivedAppModel);
        }

        public void Load()
        {
            LoadApps();
        }

        private void LoadApps()
        {
            Apps = SystemEnvHelper.App.GetInstallApps().Select(a => new AppModel
            {
                Path = a.InstallLocation,
                AboutInfo = a.URLInfoAbout,
                IconPath = a.DisplayIcon,
                InstallDate = a.InstallDate,
                LastOperatTime = null,
                Name = a.DisplayName,
                OnLine = (int)(DateTime.Now.Ticks % 3),
                Publisher = a.Publisher,
                UnInstallPath = a.UninstallString,
                Version = a.DisplayVersion
            }).Where(c => !string.IsNullOrEmpty(c.Path) || c.InstallDate.HasValue).ToList();
        }
    }
}
